<?php
/**
 * Excel
 */
namespace app\voip\func;


use app\voip\model\EChildren;
use app\voip\model\EExcelList;
use app\voip\model\EPatriarch;
use think\Db;

class ExcelListFunc
{


    /**
     * @param $uid
     * @param $title
     * @param $download_password
     * @param $download_url
     * @param $type_id
     * @param $data_intro
     * @param $remark
     * @param $number
     * @return mixed
     */
    static public function add($uid, $title, $download_password, $download_url, $type_id, $data_intro, $remark,$number)
    {
        $list=[
            'uid'=>$uid,
            'title'=>$title,
            'download_password'=>$download_password,
            'download_url'=>$download_url,
            'type_id'=>$type_id,
            'data_intro'=>$data_intro,
            'remark'=>$remark,
            'number'=>$number
        ];
        $add=EExcelList::create($list);
        return $add->id;
    }

    /**
     * @param $where
     * @param $rows
     * @param $param
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    static public function findMy($where,$rows,$param)
    {
        $obj=new EExcelList();
        return $obj->where($where)->order('id desc')->paginate($rows,false,['query'=>$param]);
    }


    /**
     * @param $where
     * @return array|false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static public function userExcelList($where)
    {
        $obj=new EExcelList();
        return $obj->where($where)->select();
    }

    /**
     * @param $where
     * @return EExcelList|null
     * @throws \think\exception\DbException
     */
    static public function find($where)
    {
        return EExcelList::get($where);
    }

    /**
     * @param $where
     * @param $rows
     * @param $param
     * @param $order
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    static public function getRelationAll($where, $rows, $param,$order)
    {
        $obj=new EPatriarch();
        return $obj->alias('p1')->join('e_correlation c1','p1.id=c1.pid')->
        join('e_children c2','c1.cid=c2.id')->
        join('e_home_address h1','p1.id=h1.pid')->
        join('e_home_address h2','c2.id=h2.cid')->
        where($where)->order($order)->field(
            'p1.id pid,p1.sex psex,p1.name pname,p1.qq pqq ,p1.email pemail,p1.phone pphone,h1.detailed_addr pdetailed_addr,p1.interest pinterest,
        c2.name cname,c2.id cid,c2.sex csex,c2.qq cqq,c2.email cemail,c2.phone cphone,h2.detailed_addr cdetailed_addr,c2.interest cinterest')->paginate($rows,false,['query'=>$param]);
    }

    /**
     * @param $where
     * @param $rows
     * @param $param
     * @param $order
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    static public function getRelationpAll($where, $rows, $param,$order)
    {
        $obj=new EPatriarch();
        return $obj->alias('p1')->
        join('e_home_address h1','p1.id=h1.pid')->
        where($where)->order($order)->field(
            'p1.id pid,p1.sex psex,p1.name pname,p1.qq pqq ,p1.email pemail,p1.phone pphone,h1.detailed_addr pdetailed_addr,p1.interest pinterest')->paginate($rows,false,['query'=>$param]);
    }

    /**
     * @param $where
     * @param $rows
     * @param $param
     * @param $order
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    static public function getRelationcAll($where, $rows, $param,$order)
    {
        $obj=new EChildren();
        return $obj->alias('c2')->
        join('e_home_address h2','c2.id=h2.cid')->
        where($where)->order($order)->field('c2.name cname,c2.id cid,c2.sex csex,c2.qq cqq,c2.email cemail,c2.phone cphone,h2.detailed_addr cdetailed_addr,c2.interest cinterest')->paginate($rows,false,['query'=>$param]);
    }


    /**
     * @param $where
     * @param $count
     * @return array|false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static public function getExcelListFind($where, $count)
    {
        $obj = new EExcelList();
        return $obj->where($where)->order('id desc')->limit(0,$count)->select();
    }
}